package com.example.tsbs.binary;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BasicFormat {

    /**名称*/
    private String name;

    /**数据维度数*/
    private Integer nDim;

    /**数据类型*/
    private String[] dType;

    /**各数据维度名称*/
    private String[] dimNames;

    /**各数据维度长度*/
    private Integer[] length;

    /**坐标轴数值*/
    private Object[] value;

    /**数据*/
    private Object data;

    public BasicFormat(String name, Integer nDim, String[] dType, String[] dimNames, Integer[] length, Object[] value, Object data) {
        setName(name);
        setNDim(nDim);
        setDType(dType);
        setDimNames(dimNames);
        setLength(length);
        setValue(value);
        setData(data);
    }

    // 合并字符串
    @Override
    public String toString() {
        return getName() + getNDim() + getDType() + getDimNames() + getLength() + getValue() + getData();
    }

    public static void main(String[] args) {
        String[] arrType = {"complex","complex"};
        String[] disNames = {"a","b"};
        Integer[] lengths = {6,2};
        Object[] value = {1.2, 1.2, 1, 12.0001, 13.02, 1.000001, 100000,200000};
        BasicFormat bs = new BasicFormat("light", 2,arrType,disNames,
                lengths, value, "  1122");
        System.out.println(bs);
        System.out.println("**************************");
    }

    public void setName(String name) {this.name = name;}
    public String getName() {return String.format("%16s", name);}

    public void setNDim(Integer nDim) {this.nDim = nDim;}
    public int getNDim() {return this.nDim;}

    public void setDType(String[] dType) {this.dType = dType;}
    public String getDType() {
        String res = "";
        for (String i : dType) {
            res += String.format("%8s", i);
        }
        res += String.format("%8s", "string");
        return res ;
    }

    public void setDimNames(String[] dimNames) {this.dimNames = dimNames;}
    public String getDimNames() {String res = "";
        for (String i : dimNames) {
            res += String.format("%16s", i);
        }
        return res ;
    }

    public void setLength(Integer[] length) {this.length = length;}
    public String getLength() {
        String res = "";
        for (Integer i : length) {
            res += String.format("%4d", i);
        }
        return res;
    }

    public void setValue(Object[] value) {this.value = value;}
    public String getValue() {
        String res = "";
        for(Object i : value) {
            res += String.format("%16s", i.toString());
        }
        return res ;
    }

    public void setData(Object data) {this.data = data;}
    public Object getData() {
        List<Object> m = new ArrayList<>();
        for (int i=0 ; i< nDim; i++) {
            List<Object> n = new ArrayList<>();
            for (int j=0 ; j< length[i]; j++) {
                n.add(value[i+j]);
            }
            m.add(n);
            System.out.println(m);
        }
        return m ;
    }

}
